/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Tools;

import java.io.File;
import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;

/**
 *
 * @author patricksamson236
 */
public class FileTools {
    // low-level System info
    private FileSystemView fsv = javax.swing.filechooser.FileSystemView.getFileSystemView();
    private String OS_NAME;
    private String OS_ARCH;
    private String OS_VERS;
    private String FILE_SEPAR;
    private String PATH_SEPAR;
    private String USER_NAME;
    private String USER_HOME_DIR;
    private String CURRENT_DIR;

    public FileTools() {
        OS_NAME = System.getProperty("os.name");
        OS_ARCH = System.getProperty("os.arch");
        OS_VERS = System.getProperty("os.version");
        FILE_SEPAR = System.getProperty("file.separator");
        PATH_SEPAR = System.getProperty("path.separator");
        USER_NAME = System.getProperty("user.name");
        USER_HOME_DIR = System.getProperty("user.home");
        CURRENT_DIR = System.getProperty("user.dir");
    }

    public String formatPath(String path) {
        if ("\\".equals(FILE_SEPAR)) {
            return path;
        } else {
            return path.replace("\\", FILE_SEPAR);
        }
    }

    public File showFileChooser(File file) {
        // create the filechooser
        JFileChooser fileChooser = new JFileChooser(file);
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        // make it visible
        int answer = fileChooser.showSaveDialog(fileChooser);

        // handle the answers
        if (answer == JFileChooser.APPROVE_OPTION) {
            file = fileChooser.getSelectedFile();
        }

        // return a new, valid file, or the old one
        return file;
    }

    public String getUserDir() {
        return USER_HOME_DIR;
    }
    
    public Icon getFileIcon(File f){
        return fsv.getSystemIcon(f);
    }
    
    public File getDesktop(){
        return fsv.getRoots()[0];
    }
    
    public String getOSVersion(){
        return OS_VERS;
    }
    
    public String getOSName(){
        return OS_NAME;
    }
    
    public String getScitnerDownDir(){
        return formatPath(USER_HOME_DIR + "\\Scitner Downloads");
    }
}
